<html>
<head>
<title>Show Elements</title>

<?php
//GET Variables
$project_id = $_GET['project_id'];
$limit =$_POST['limit'];
echo '<table><tr><td>The Elements that will be structured are:<br>';
//Database connection
$dbc = mysqli_connect('localhost', 'root', '', 'ism')
	or die("Connection failed");
$query = "SELECT * FROM element WHERE project_id='$project_id'";
$result = mysqli_query($dbc, $query)
	or die("Query failed!");
$i = 1;	
while($row = mysqli_fetch_array($result)){
	echo $i.'. '.$row['statement']."<br />";
	$i++;
}
echo '<a href=../structure/structure.php?project_id='.$project_id.'>Start accepting or rejecting statements</a></td><td>';
echo '<td> The original matrix is:<table>';
$j=1;

for($i=1;$i<=$limit;$i++){
	echo'<tr>';
		for($j=1;$j<=$limit;$j++){
			echo('<td>');
			if($i==$j){
				$query = "INSERT INTO element_rel VALUES('','$project_id', '$i', '$j', '1')"; 
				$result = mysqli_query($dbc, $query)
				or die('Query failed!');
				$query = "SELECT * FROM element_rel WHERE project_id='$project_id' AND first_element='$i' AND second_element='$j'";
				$result = mysqli_query($dbc, $query)
				or die('Query failed!');
				while($row = mysqli_fetch_array($result)){
				echo $row['relation'];
				}
			}
			else{
				$query = "INSERT INTO element_rel VALUES('','$project_id', '$i', '$j', '0')"; 
				$result = mysqli_query($dbc, $query)
				or die('Query failed!');
				$query = "SELECT * FROM element_rel WHERE project_id='$project_id' AND first_element='$i' AND second_element='$j'";
				$result = mysqli_query($dbc, $query)
				or die('Query failed!');
				while($row = mysqli_fetch_array($result)){
				echo $row['relation'];
				}
			}
			echo('</td>');
		}
	echo('</tr>');
	}
	
echo'</table></td></tr></table>';
?>
</head>
<body>
</body>
</html>
